#include <IRremote.h>

int IN1 = 8; //input1 подключен к выводу 8 
int IN2 = 7;
int IN3 = 2;
int IN4 = 4;
int EN1 = 9;
int EN2 = 6;
int RECEIVE_PIN = 11;

IRrecv irrecv(RECEIVE_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode (EN1, OUTPUT);
  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  pinMode (EN2, OUTPUT);
  pinMode (IN4, OUTPUT);
  pinMode (IN3, OUTPUT);
}

void up() / / Forward 
{
  Serial.println("Up");
  digitalWrite (IN2, HIGH);
  digitalWrite (IN1, LOW); 
  digitalWrite (IN4, HIGH);
  digitalWrite (IN3, LOW); 
  analogWrite(EN1,255);
  analogWrite(EN2,255);
}

void down() / / Forward 
{
  Serial.println("Down");
  digitalWrite (IN2, LOW);
  digitalWrite (IN1, HIGH); 
  digitalWrite (IN4, LOW);
  digitalWrite (IN3, HIGH); 
  analogWrite(EN1,255);
  analogWrite(EN2,255);
}

void left() / / Forward 
{
  Serial.println("Left");
  digitalWrite (IN2, HIGH);
  digitalWrite (IN1, LOW); 
  digitalWrite (IN4, LOW);
  digitalWrite (IN3, HIGH); 
  analogWrite(EN1,255);
  analogWrite(EN2,255);
}

void right() / / Forward 
{
  Serial.println("Right");
  digitalWrite (IN2, LOW);
  digitalWrite (IN1, HIGH); 
  digitalWrite (IN4, HIGH);
  digitalWrite (IN3, LOW); 
  analogWrite(EN1,255);
  analogWrite(EN2,255);
}

void stop() / / Forward 
{
  Serial.println("Stop");
  digitalWrite (IN2, LOW);
  digitalWrite (IN1, LOW); 
  digitalWrite (IN4, LOW);
  digitalWrite (IN3, LOW); 
  analogWrite(EN1,0);
  analogWrite(EN2,0);
}

void loop()
{
  if (irrecv.decode(&results)) {
    switch (results.value) {
      case 0xE0E006F9:
      up(); 
      break;
      
      case 0xE0E08679:
      down(); 
      break;
      
      case 0xE0E0A659:
      left(); 
      break;
      
      case 0xE0E046B9:
      right(); 
      break;
      
      case 0xE0E016E9:
      stop(); 
      break;
    }
    irrecv.resume();
  }
}
